<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class GrowController extends Controller
{
    //
    public function run(){
      $today = date('Y-m-d');
      $tasks = DB::table('tasks')->where('enddate','>=',$today)->get();

       foreach ($tasks as $t) {

        // $data = DB::table('grows')->where(['uid'=>$t->uid,'pid'=>$t->pid,'paytime'=>$today])->first();
        //如果三个条件同时成立,并且查出一条数据,说明已经得到收益,不会再次得到收益
        if(!DB::table('grows')->where(['uid'=>$t->uid,'pid'=>$t->pid,'paytime'=>$today])->first()){

          $row = [];
          $row['uid'] = $t->uid;
          $row['pid'] = $t->pid;
          $row['title'] = $t->title;
          $row['amount'] = $t->amount;
          $row['paytime'] = $today;
          DB::table('grows')->insert($row);
        }
       }
    }
}
